// example.cpp
// Examples of random number generation with MersenneTwister.h
// Richard J. Wagner  15 May 2003

#define SIZE 1000000

#include <iostream>
#include <fstream>

#include "MersenneTwister.h"



using namespace std;

int main(void)
{
	MTRand mymtrand;	
	double buffer[SIZE];
	//~ FILE *fp;
	
	
	
	ifstream stateIn( "state.data" );
	if( stateIn )
	{
		stateIn >> mymtrand;
		stateIn.close();
	}
		
    
	//~ if ((fp = fopen("random.data", "w+b")) ==NULL){
		//~ printf("Error opening file\n");
		//~ exit(1); 
	//~ }
	
	
	 for (long i=0; i<SIZE; i++) {
		buffer[i]=mymtrand.randExc();
	}
        //~ fwrite(&buffer, sizeof(buffer), 1,fp);
	//~ fclose(fp);
	
	
	ofstream dataOut( "random.data" , ios::out | ios::binary);
	if(dataOut)
	{
		dataOut.write((char*)buffer,SIZE*sizeof(double));
		dataOut.close();
	}
	
	

	// A stream is convenient for saving to a file.
	ofstream stateOut( "state.data" );
	if( stateOut )
	{
		stateOut <<mymtrand;
		stateOut.close();
	}
	
	return 0;

	// In summary, the recommended common usage is

	//MTRand mtrand5;  // automatically generate seed
	//double l = mtrand5();               // real number in [0,1]
	//double m = mtrand5.randExc(0.5);    // real number in [0,0.5)
	//unsigned long n = mtrand5.randInt(10);  // integer in [0,10]	

}

